import pymysql
import xlwt

conn = pymysql.connect(host="121.4.69.146", user='root', password='xhhg@2020', port=3306, db="big_data",
                       use_unicode=True, charset='utf8')
cur = conn.cursor()

info_list = []
with open("sqh.txt", "r") as fw:
    ss = 0
    print("1")
    for application_number in fw:
        item = {}
        sqh = application_number.strip()
        sql = f"SELECT money_type, money, close_date FROM `annual_fee_information` WHERE application_number = '{sqh}' LIMIT 1"
        cur.execute(sql)
        returndata = cur.fetchall()
        item['1'] = returndata[0][0]
        item['2'] = returndata[0][1]
        item['3'] = returndata[0][2]
        print(returndata)
        info_list.append(item)


print(info_list)

workbook = xlwt.Workbook()
sheet = workbook.add_sheet("sheet1")
sheet.write(0, 0, '1')
sheet.write(0, 1, '申请人')
sheet.write(0, 2, '申请日')
if len(info_list) > 0:
    for i in range(len(info_list)):
        sheet.write(i + 1, 1, info_list[i]['1'])
        sheet.write(i + 1, 2, info_list[i]['2'])
        sheet.write(i + 1, 3, info_list[i]['3'])
    workbook.save("1111.xls")

